package org.xiyinjihe.platform.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xiyinjihe.platform.dao.SutraDetailMapper;
import org.xiyinjihe.platform.dao.SutraMapper;
import org.xiyinjihe.platform.po.*;
import org.xiyinjihe.platform.service.SutraService;

import java.util.List;

@Service
public class SutraServiceImpl implements SutraService {

    @Autowired
    private SutraMapper sutraMapper;

    @Autowired
    private SutraDetailMapper sutraDetailMapper;

    @Override
    public List<Sutra> getSutraList(String sutraType) {
        SutraExample example = new SutraExample();
        SutraExample.Criteria criteria = example.createCriteria();
        criteria.andIdIsNotNull();
        if(sutraType != null && !sutraType.isEmpty()){
            criteria.andTypeEqualTo(sutraType);
        }
        return sutraMapper.selectByExample(example);
    }

    @Override
    public List<SutraDetail> getSutraDetail(Long sutraId, String chapter) {
        SutraDetailExample example = new SutraDetailExample();
        SutraDetailExample.Criteria criteria = example.createCriteria();
        criteria.andSutraIdEqualTo(sutraId);
        if(chapter != null && !chapter.isEmpty())
            criteria.andChapterEqualTo(chapter);
        return sutraDetailMapper.selectByExampleWithBLOBs(example);
    }

    @Override
    public Sutra getSutra(Long sutraId) {
        return sutraMapper.selectByPrimaryKey(sutraId);
    }
}
